﻿namespace Cmn
{
    using System;
    using System.Web;

    public class Cookies
    {
        public static void Clear(string infoName)
        {
            HttpCookie cookie = new HttpCookie(infoName) {
                Expires = DateTime.Now.AddYears(-10)
            };
            HttpContext.Current.Response.Cookies.Add(cookie);
        }

        public static void Clear(string domain, string infoName)
        {
            HttpCookie cookie = new HttpCookie(infoName) {
                Domain = domain,
                Expires = DateTime.Now.AddYears(-10)
            };
            HttpContext.Current.Response.Cookies.Add(cookie);
        }

        public static string Get(string infoName)
        {
            if (HttpContext.Current.Request.Cookies[infoName] != null)
            {
                return HttpContext.Current.Request.Cookies[infoName].Value.ToString();
            }
            return "";
        }

        public static void Set(string infoName, string infoValue)
        {
            Set(infoName, infoValue, 0x16d);
        }

        public static void Set(string infoName, string infoValue, int days)
        {
            HttpCookie cookie = new HttpCookie(infoName) {
                Value = infoValue,
                Expires = DateTime.Now.AddDays((double) days)
            };
            HttpContext.Current.Response.Cookies.Add(cookie);
        }

        public static void Set(string domain, string infoName, string infoValue)
        {
            Set(domain, infoName, infoValue, 0x16d);
        }

        public static void Set(string domain, string infoName, string infoValue, int days)
        {
            HttpCookie cookie = new HttpCookie(infoName) {
                Domain = domain,
                Value = infoValue,
                Expires = DateTime.Now.AddDays((double) days)
            };
            HttpContext.Current.Response.Cookies.Add(cookie);
        }
    }
}

